from django.contrib import admin
from .models import *
from tuntun.settings import DJANGO_NO_RECHARGE_USER_GROUP_NAME, DJANGO_PRODUCT_MGR_USER_GROUP_NAME, DJANGO_REPO_USER_GROUP_NAME, DJANGO_SUPER_USER_GROUP_NAME

# Register your models here.

class UserAdmin(admin.ModelAdmin):
    list_display = ['mobile', 'real_name', 'state', 'getui_clientid']
    readonly_fields = ('grow_coin','tun_level')

    def get_readonly_fields(self, request, obj=None):
        if request.user.groups.all().filter(name=DJANGO_NO_RECHARGE_USER_GROUP_NAME):
            return ['balance', ""]
        return []
admin.site.register(User, UserAdmin)


class TunLevelAdmin(admin.ModelAdmin):
    list_display = ['id', 'name', 'need_grow_coin']
    fields = ['name', 'icon_public_file_id', 'need_grow_coin']
admin.site.register(TunLevel, TunLevelAdmin)


class UserTunLevelRightAdmin(admin.ModelAdmin):
    list_display = ('user',
                    'tun_level',
                    'take_out_free_postage_times_1y',
                    'free_get_try_drink_count',
                    'free_offline_experience_times_1y',
                    'procedure_preferential_percent',
                    'repo_preferential_percent',
                    'first_publish_product_pre_buy_times_1y')
# admin.site.register(UserTunLevelRight, UserTunLevelRightAdmin)


class WithdrawCashAdmin(admin.ModelAdmin):
    list_display = ('user', 'amount', 'to_account', 'account_type', 'state', 'date', 'provider_order_id', 'provider_response_data', 'provider_response_msg')
admin.site.register(WithdrawCash, WithdrawCashAdmin)


class UserBalanceRecordAdmin(admin.ModelAdmin):
    list_display = ('get_add_time', 'user', 'create_type', 'amount', 'order_id', 'recharge_method',)
admin.site.register(UserBalanceRecord, UserBalanceRecordAdmin)


class AuthCodeAdmin(admin.ModelAdmin):
    list_display = ('mobile', 'code', 'get_add_time')
admin.site.register(AuthCode, AuthCodeAdmin)